//
//  UIBarButtonItem+Extensions.swift
//  itcastWeibo
//
//  Created by 谢臣 on 2019/10/17.
//  Copyright © 2019 itcast. All rights reserved.
//


import UIKit
extension UIBarButtonItem{
    /// 创建UIBarButtonItem
    ///
    /// - Parameters:
    ///   - title: title ：title
    ///   - fontSize: fontSize ：fontSize默认16号
    ///   - target: target ：target
    ///   - action: action ：action
    ///   - isBack: isBack ：是否为返回按钮，如果是加上<
    convenience init(title:String, fontSize:CGFloat = 16.0,target: AnyObject,action:Selector,isBack: Bool = false){
        let btn : UIButton = UIButton.cz_textButton(title, fontSize: fontSize, normalColor: UIColor.darkGray, highlightedColor: UIColor.orange)
        
        if isBack {
            var imageName = "navigationbar_back_withtext_highlighted"
            btn.setImage(UIImage(named: imageName), for: UIControl.State(rawValue: 0))
            btn.setImage(UIImage(named: imageName+"_highlighted"), for: .highlighted)
            btn.sizeToFit()
        }
        
        btn.addTarget(target, action:action, for: .touchUpInside)
        self.init(customView: btn)
    }
}
